package com.blog.module.user.service;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.blog.common.mybatis.Page;
import com.blog.common.mybatis.ParsePagination;
import com.blog.module.user.mapper.UserMapper;
import com.blog.module.user.pojo.User;
import com.blog.module.user.pojo.UserExample;

@Service
public class UserService {

    @Autowired
	private UserMapper userMapper;

	public Page queryPageUser() {
		ParsePagination pagination = new ParsePagination();
		int pageNo = pagination.getPageNo();
		int pageSize = pagination.getPageSize();
		UserExample example = new UserExample();
		int count = userMapper.countByExample(example);
		List<User> list = new ArrayList<User>();
		Page page = new Page(count, pageNo, pageSize, list);
		example.setLimitStart((pageNo - 1) * pageSize);
		example.setLimitEnd(pageSize);
		list = userMapper.selectByExample(example);
		page.setList(list);
		return page;
	}

	public int insert(User user) {
		int count = userMapper.insert(user);
		if (count == 1) {
			return count;
		}
		return 0;
	}

	public int update(User user) {
		int count = userMapper.updateByPrimaryKeySelective(user);
		if (count == 1) {
			return count;
		}
		return 0;
	}
}
